home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 218 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.9 KB

  1. Path: fido.asd.sgi.com!austern
  2. From: kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: An STL helper -- and template and type shenanigans
  5. Date: 01 Feb 1996 09:23:34 PST
  6. Organization: SEL
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <KANZE.96Feb1141158@slsvewt.lts.sel.alcatel.de>
  9. References: <01BAEFD6.AD7E8620@dino.int.com>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: 01 Feb 1996 13:11:58 GMT
  12. In-Reply-To: Eugene Lazutkin's message of 31 Jan 1996 12:04:06 PST
  13. Apparently-To: std-c++@ncar.UCAR.EDU
  14. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  15.     iQBVAwUBMRD3I0y4NqrwXLNJAQF8hwH+IhiXe8YOoMT8G6JLLKB9uhfvcQZu2rT9
  16.     xc/qy5NJRgehObxK+/8yyzLhU538xAu7UQLrRAJE/Aqa+HQVu9d9TA==
  17.     =KLK5
  18. Originator: austern@isolde.mti.sgi.com
  19.  
  20. In article <01BAEFD6.AD7E8620@dino.int.com> Eugene Lazutkin
  21. <eugene@int.com> writes:
  22.  
  23. |> Why do I use wrappers?  Just small example: vector< auto_ptr< T > > 
  24. |> (or list< auto_ptr< T > >).  I f you tried it, you'd discover that STL 
  25. |> (I use ObjectSpace's implementation) uses copy-ctor with a const parameter 
  26. |> and auto_ptr doesn't define it.
  27.  
  28. |> BTW, how come that auto_ptr from Standard C++ Library is incompatible with
  29. |> vector<>, list<> and other STL containers from the same source? Or maybe I
  30. |> have incorrect implementation?
  31.  
  32. And just when I thought I'd found a solution to the auto_ptr
  33. problem:-).
  34.  
  35. In fact, this is a weakness in the STL definition (IMHO).  STL
  36. containers require *real* copy constructors, that actually copy.  For
  37. something like auto_ptr, this is not reasonable.  Even supposing that
  38. STL and the language could handle it, what would be the meaning of:
  39.  
  40.     vector< auto_ptr< T > >
  41.                         v( 10 , auto_ptr< T >( new T ) ) ;
  42.  
  43. Certainly not what it would seem to be.
  44.  
  45. A possible solution would be to have two functions everywhere where
  46. the STL requires a fill object.  (The current version has one
  47. function, with a default parameter T() as fill.)  The version without
  48. the fill object parameter would use the default constructor, rather
  49. than copy.  Obviously, this is only interesting if the implementation
  50. only instantiates functions that are actually used.  (I believe that
  51. this is supposed to be the case, although I know that many
  52. implementations do not do this.)
  53.  
  54. This still leaves a problem with the internal functions, such as
  55. reserve, which may copy the data.  While not a problem for auto_ptr
  56. (since they are copying non-const lvalues), it may be a problem for
  57. other classes.
  58. --
  59. James Kanze         Tel.: (+33) 88 14 49 00        email: kanze@gabi-soft.fr
  60. GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
  61. Conseils, itudes et rialisations en logiciel orienti objet --
  62.                 -- A la recherche d'une activiti dans une region francophone
  63. ---
  64. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  65.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  66.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  67.